package com.iso8583.util;


public class ByteShow {
	public static String show(byte[] b)
	{
		char[] ch = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
		
					java.io.StringWriter stream = new java.io.StringWriter();
			
					int len = b.length;
					for(int i = 0; i < len ; i++)
					{
						byte c = (byte)((b[i] & 0xf0) >> 4);
						stream.write(ch[c]);
						c = (byte)(b[i] & 0x0f);
						stream.write(ch[c]);
					}
					return stream.toString();
	}
	
	public static String show(byte[] b,int maxLen)
		{
			char[] ch = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
		
			java.io.StringWriter stream = new java.io.StringWriter();
			
			int len = b.length > maxLen?maxLen:b.length;
			for(int i = 0; i < len ; i++)
			{
				byte c = (byte)((b[i] & 0xf0) >> 4);
				stream.write(ch[c]);
				c = (byte)(b[i] & 0x0f);
				stream.write(ch[c]);
			}
			if(b.length > maxLen)
				stream.write("...");
			 
			return stream.toString();
		}
	
}
